package edu.mju.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.mju.commonutils.ReturnCode;
import edu.mju.eduservice.entity.StudyCourse;
import edu.mju.eduservice.entity.StudyTeacher;
import edu.mju.eduservice.service.StudyCourseService;
import edu.mju.eduservice.service.StudyTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: wyp
 * @Date: 2020/9/20 15:01
 *
 * EnableDiscoveryClient:nacos注册
 */
@RestController
@RequestMapping("/eduservice/front/index")
public class IndexController {

    @Autowired
    private StudyCourseService studyCourseService;

    @Autowired
    private StudyTeacherService studyTeacherService;

    /**
     *  查询排名前8的课程
     *  查询排名前8的教师
     * @return
     */
    @GetMapping("/indexInfo")
    public ReturnCode indexInfo(){
        //查询排名前12的课程
        QueryWrapper<StudyCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("view_count");
        wrapper.last(" limit 8");
        List<StudyCourse> studyCourseList = studyCourseService.list(wrapper);

        //查询排名前8的教师
        QueryWrapper<StudyTeacher> wrapper2 = new QueryWrapper<>();
        wrapper2.orderByDesc("level");
        wrapper2.last(" limit 8");
        List<StudyTeacher> studyTeacherList = studyTeacherService.list(wrapper2);

        Map<String,Object> map = new HashMap<>();
        map.put("studyCourseList",studyCourseList);
        map.put("studyTeacherList",studyTeacherList);

        return ReturnCode.success().data(map);
    }
}
